package com.webchat.netty.server.service;

import com.webchat.common.enums.RedisKeyEnum;
import com.webchat.netty.server.service.redis.HashRedisService;

public class ChannelRegistryService {

    public void registry(String userId, String instanceInfo) {

        String userChannelKey = RedisKeyEnum.USER_NETTY_CHANNEL_INSTANCE_HASH_CACHE.getKey();
        HashRedisService.set(userChannelKey, userId, instanceInfo, RedisKeyEnum.USER_NETTY_CHANNEL_INSTANCE_HASH_CACHE.getExpireTime());
    }

    /**
     * 删除
     *
     * @param userId
     */
    public void remove(String userId) {

        String userChannelKey = RedisKeyEnum.USER_NETTY_CHANNEL_INSTANCE_HASH_CACHE.getKey();
        HashRedisService.del(userChannelKey, userId);
    }

    /**
     * 查询用户当前ws session所在节点信息
     *
     * @param userId
     * @return
     */
    public String getInstance(String userId) {

        String userChannelKey = RedisKeyEnum.USER_NETTY_CHANNEL_INSTANCE_HASH_CACHE.getKey();
        return HashRedisService.get(userChannelKey, userId);
    }

}
